package com.meilai.project.controller.web.business.customer;


import com.meilai.project.dto.CommonResult;
import com.meilai.project.dto.business.customer.CustomerInfoFlowDTO;
import com.meilai.project.service.business.customer.CustomerInfoFlowService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xhy
 * @since 2022-01-06
 */
@RestController
@RequestMapping("api/web/customerInfoFlow")
public class CustomerInfoFlowController {

    @Autowired
    private CustomerInfoFlowService service;


    @PostMapping("/save")
    @ApiOperation("临时保存")
    public CommonResult save(@RequestBody CustomerInfoFlowDTO dto, @RequestParam(value = "wfData_id", required = false) Long wfData_id) {
        return new CommonResult().success(service.save(dto, true, wfData_id));
    }

    @PostMapping("/saveAndStartFlow")
    @ApiOperation("保存并开启流程")
    public CommonResult saveAndStartFlow(@RequestBody CustomerInfoFlowDTO dto, @RequestParam(value = "wfData_id", required = false) Long wfData_id) {
        return new CommonResult().success(service.saveAndStartFlow(dto, wfData_id));
    }

    @PostMapping("/check")
    @ApiOperation("审批")
    public CommonResult check(@RequestBody CustomerInfoFlowDTO dto,
                              @RequestParam(value = "isCover") Boolean isCover,
                              @RequestParam(value = "isReturn") Boolean isReturn,
                              @RequestParam(value = "opinion", required = false) String opinion) {
        return new CommonResult().success(service.check(dto, isCover, isReturn, opinion));
    }

    @PostMapping("/remove")
    @ApiOperation("删除记录")
    public CommonResult remove(@RequestParam(value = "flow_id") Long flow_id, @RequestParam(value = "wfData_id", required = false) Long wfData_id) {
        return new CommonResult().success(service.remove(flow_id, wfData_id));
    }

    @GetMapping("/page")
    @ApiOperation("分页查询")
    public CommonResult page(@RequestParam(name = "page", defaultValue = "1") Integer page,
                             @RequestParam(name = "page_size", defaultValue = "10") Integer page_size,
                             @RequestParam(name = "is_my_customer_page") Boolean is_my_customer_page,
                             @RequestParam(name = "name", required = false) String name,
                             @RequestParam(name = "industry_id", required = false) Long industry_id) {
        return new CommonResult().success(service.page(page, page_size, name, industry_id, is_my_customer_page));
    }

    @GetMapping("/one")
    @ApiOperation("根据审批ID获取客户信息")
    public CommonResult one(@RequestParam(name = "id") Long id) {
        return new CommonResult().success(service.getOneDtoById(id));
    }

    @GetMapping("/draftsIsNull")
    @ApiOperation("判断用户草稿箱是否为空,不为空返回记录的ID,空的话返回-1")
    public CommonResult draftsIsNull() {
        return new CommonResult().success(service.draftsIsNull());
    }

    @PostMapping("/equalsData")
    @ApiOperation("判断用户基本数据信息是否有修改")
    public CommonResult equalsData(@RequestBody CustomerInfoFlowDTO dto) {
        return new CommonResult().success(service.equalsData(dto));
    }

    @GetMapping("/getFlowCheckCount")
    @ApiOperation("获取列表中待审核的数量")
    public CommonResult getFlowCheckCount(@RequestParam(name = "is_my_customer_page") Boolean is_my_customer_page) {
        return new CommonResult().success(service.getFlowCheckCount(is_my_customer_page));
    }

    @GetMapping("/getFlowIsEnd")
    @ApiOperation("获取当前操作人是否是最后一个")
    public CommonResult getFlowIsEnd(@RequestParam(name = "id") Long id) {
        return new CommonResult().success(service.getFlowIsEnd(id));
    }

    @PostMapping("/actualDelete")
    @ApiOperation("彻底删除记录")
    public CommonResult actualDelete(@RequestParam(value = "flow_id") Long flow_id, @RequestParam(value = "wfData_id", required = false) Long wfData_id) {
        return new CommonResult().success(service.actualDelete(flow_id, wfData_id));
    }

    @GetMapping("/getHistoryUser")
    @ApiOperation("获取历史对接人信息")
    public CommonResult getHistoryUser(@RequestParam(name = "customer_id") Long customer_id) {
        return new CommonResult().success(service.getHistoryUser(customer_id));
    }
}

